package com.james.wee.shuangseqiu.dafenqissq;

import java.util.ArrayList;
import java.util.List;

import com.james.wee.shuangseqiu.bo.OpenNumber;
import com.james.wee.shuangseqiu.open.OpenData;

public class DaFenQiSSQ {

	private OpenNumber prevObj;
	private List<Integer> arrayNum;

	public DaFenQiSSQ(OpenNumber prevObj) {
		this.prevObj = prevObj;
		arrayNum = new ArrayList<Integer>();
		String[] red = prevObj.sixRedNum().split(",");
		for (String a : red)
			arrayNum.add(Integer.parseInt(a.trim()));
	}

	private String toTen(int a) {
		String c = "" + a;
		if (a < 10)
			c = "0" + a;
		return c;
	}

	/**
	 * 第一密码
	 * 
	 * @return
	 */
	public String calcOpenNumFirstPWD() {

		int a = 0;
		int b = 0;
		List<String> list = new ArrayList<String>();
		for (int i = 0, len = arrayNum.size(); i < len - 1; i++) {
			a = arrayNum.get(i);
			for (int j = i + 1, lfn = arrayNum.size(); j < lfn; j++) {
				b = a + arrayNum.get(j);
				if (b <= 33)
					// if (!list.contains(b))
					list.add(toTen( b));
			}
		}
		return subString(list.toString());
	}

	/**
	 * 第二密码
	 * 
	 * @return
	 */
	public String calcOpenNumTwoPWD() {
		int a = 0;
		int b = 0;
		List<String> list = new ArrayList<String>();
		for (int i = 0, len = arrayNum.size(); i < len - 1; i++) {
			a = arrayNum.get(i).intValue();
			for (int j = i + 1, lfn = arrayNum.size(); j < lfn; j++) {
				b = Math.abs(a - arrayNum.get(j));
				// if (!list.contains(b))
				list.add(toTen( b));
			}
		}
		java.util.Collections.sort(list);
		return subString(list.toString());
	}

	/**
	 * 第三密码
	 * 
	 * @return
	 */
	public String calcOpenNumThreePWD() {
		int a = 0;
		int b = 0;
		List<String> list = new ArrayList<String>();
		for (int i = 0, len = arrayNum.size(); i < len - 1; i++) {
			a = arrayNum.get(i);
			for (int j = i + 1, lfn = arrayNum.size(); j < lfn; j++) {
				b = a * arrayNum.get(j);
				if (b <= 33)
					// if (!list.contains(b))
					list.add(toTen( b));
			}
		}
		return subString(list.toString());
	}

	/**
	 * 第四密码
	 * 
	 * @return
	 */
	public String calcOpenNumFourPWD() {
		int a = 0;
		int b = 0;
		int c = 0;
		List<String> list = new ArrayList<String>();
		for (int i = arrayNum.size() - 1; i > 0; i--) {
			a = arrayNum.get(i);
			for (int j = i - 1; j >= 0; j--) {
				b = arrayNum.get(j);

				if (a % b == 0) {
					c = a / b;
					// if (!list.contains(c))
					list.add(toTen( c));
				}
			}
		}

		return subString(list.toString());
	}

	private String subString(String str) {
		return str.substring(1, str.length() - 1).replaceAll(" ", "");
	}

	public static void main(String[] args) {
		OpenNumber on = null;
		try {
			on = new OpenNumber("2012145", "05", "20", "26", "27", "28", "33",
					"03", 0,null,null);// new OpenData().getMaxId();
		} catch (Exception e) {
			e.printStackTrace();
		}
		DaFenQiSSQ ds = new DaFenQiSSQ(on);
		System.out.println(ds.calcOpenNumFirstPWD());
		System.out.println(ds.calcOpenNumTwoPWD());
		System.out.println(ds.calcOpenNumThreePWD());
		System.out.println(ds.calcOpenNumFourPWD());
	}
}
